package ch.selise.archtool.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;

import ch.selise.archtool.lib.product.House;
import ch.selise.archtool.lib.product.furniture.FurnitureUnit;
import ch.selise.archtool.ui.states.BuilderChooseState;
import ch.selise.archtool.ui.states.FurnitureSelectionState;
import ch.selise.archtool.ui.states.ReportModuleState;
import ch.selise.archtool.ui.states.State;
import ch.selise.designpattern.report.Exporter;
import ch.selise.designpattern.report.ExporterFactory;

public class Context {
	BuilderChooseState builderChooseState = new BuilderChooseState(this);
	FurnitureSelectionState furnitureSelectionState = new FurnitureSelectionState(
			this);
	ReportModuleState reportModuleState = new ReportModuleState(this);

	State state = // furnitureSelectionState;
	builderChooseState;

	JButton doneButton = new JButton("Done");
	JButton cancleButton = new JButton("Cancle");

	House house;

	public Context() {
		cancleButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				state.cancel();

			}
		});
		
		doneButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				state.process();

			}
		});
	}
	
	public JButton getDoneButton() {
		
			
		return doneButton;
	}

	public JButton getCancleButton() {
		
			
		return cancleButton;
	}

	public void doneBuildingHouse(House house) {
		this.house = house;
		state = furnitureSelectionState;
		state.show();
	}

	public void AddFurnitureToHouse(List<FurnitureUnit> furnitures) {
		// house.addFurnitures(furnitures);
		this.house.addFurnitures(furnitures);
		System.out.println("add furnitures..");
		
		state = reportModuleState;
		state.show();
	}
	
	public void PrintReport(String exporterStr){
		Exporter exporter = ExporterFactory.getExporter(exporterStr);
		house.toString();
		exporter.export(house);
	}
	
	
}
